<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 一个长度为N的数组，其值涵盖[k, N-2+k]的非负整数，即意味着有2个项是重复的整数值。请找出他，禁止使用Array原型上的方法，时间复杂度O(N)。
// 例如以下数组，找出3
[3,6,3,4,5,7,2] -->
    <script>
      function fun(arr) {
        let sum1 = 0;
        let min = Infinity;
        for (let i = 0; i < arr.length; i++) {
          sum1 += arr[i];
          min = Math.min(min, arr[i]);
        }
        let sum2 = 0;
        for (let i = 0; i < arr.length - 1; i++) {
          sum2 += min++;
        }
        return sum1 - sum2;
      }
      console.log(fun([3, 6, 6, 4, 5, 7, 2]));
    </script>
  </body>
</html>
